package com.shop.service.impl;

import com.shop.dao.BizUserDao;
import com.shop.dao.impl.BizUserDaoImpl;
import com.shop.entity.Store;
import com.shop.entity.User;
import com.shop.exception.*;
import com.shop.service.BizUservice;

import java.sql.SQLException;

public class BizServiceimpl implements BizUservice {
    BizUserDaoImpl dao = new BizUserDaoImpl();
//修改商家个人页面，展示商家个人信息
    @Override
    public Store selectStore(int u_id) throws ErrorSidException {
     if(null==dao.selectBizbyid(u_id)){
         throw  new ErrorSidException("错误的商家id");
     }
        Store store =dao.selectBizbyid(u_id);

    return  store;
    }

    @Override
    public Store againupdate(int s_id, String s_storename) {
       dao.againupdate(s_id,s_storename);

        Store  store =dao.againupdateselect( s_id);
        return  store;
    }


    @Override
    public Store register(Store store) throws SQLException, useIsNoException {
        String Bizuser=store.getS_name();
        Store store1 = new Store();
        //插入用户
        dao.register(store);
        //查询是否成功
        if (null==dao.selectBizUserid(Bizuser)){
            throw new useIsNoException();
        }
       store1 =dao.selectBizUserid(Bizuser);
        return  store1;
    }

    @Override
    public Store update(Store store) throws SQLException, NDUException {
         String name =store.getS_name();
        Store store1 =null;
         dao.registers(store);
          store1 =dao.selectBizUserid(name);
         return store1;
    }


}
    //  @Override

//    }

    //    public void add(Store store) throws  {
//        //1.根据用户名查找用户信息是否存在
//        User destUser = dao.
//        //2.判断destUser是否为空
//        if(destUser != null){
//            throw new UserNameIsExistException("用户名已存在！");
//        }
//        //3.插入数据
//        userDAO.insert(user);
//    }
//    }}

//  }

//    public Store login(String u_id) throws BizLoginException {
//        //1根据用户名和密码是否相同来查找用户信息是否存在
//        Store store1 = dao.UserLogin(u_id);
//        if (store1 == null) {
//            throw new BizLoginException("登录失败");
//        }
//        return store1;
//    }